package com.nuist.springbootbook.service;

import com.nuist.springbootbook.dao.BookDao;
import com.nuist.springbootbook.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class BookService {
    @Autowired
    private BookDao bookDao;

    public List<BookInfo> getBookList() {
//        BookDao bookDao = new BookDao();
//        由于DI的原因 Component 的原因, 这里不需要 谁使用谁创建了, 由Spring 统一管理 (IOC)
//        List<BookInfo> books = new BookDao().mockData();
        List<BookInfo> books = bookDao.mockData();
        for (BookInfo book : books) {
            if (book.getStatus() == 0) {
                book.setStatusCN("不可借阅");
            } else {
                book.setStatusCN("可以借阅");
            }
        }
        return books;
    }
}

